<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use app\admin\controller\Base;
use think\Paginator;
class Comment extends Base
{

    public function comment_manage()
    {

        header("content-type:text/html;charset=utf-8");

        $where=[];
        $con=input('get.con');
        if(!empty($con))
        {
             $where['g.goods_name']=array('like',"%$con%");
        }
        $page=input('get.page',1);

        $limit=3;

        $off=($page-1)*$limit;

        $top=$page-1<1?1:$page-1;

        $list=Db::table('comment')->where('flag','=',0)->select();
        $num=count($list);
        $last=ceil($num/$limit);

        $down=$page+1>$last?$last:$page+1;

        $arr=[ 'top'=>$top, 'down'=>$down, 'page'=>$page,'last'=>$last ,'num'=>$num,'limit'=>$limit];

        $data=Db::table('comment c')
                ->where('flag','=',0)
                ->where($where)
                ->limit($off,$limit)
                ->join('goods g','c.goods_id = g.goods_id')
                ->select();
        // var_dump($data);die;
        $data=['arr'=>$arr,'list'=>$data];  
        // var_dump($data);die;
        
         if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
        {
            echo json_encode($data);
        }else{

           
            $this->assign(['arr'=>$data]);
            return $this->fetch();
        }
    }

    public function del()
    {
        $id=$_GET['id'];

//        var_dump($id);
        $resulta = Db::name('comment')
            ->where('comment_id', $id)
            ->update(['flag'=>1]);
        if($resulta)
        {
            return $this->success('删除成功！','comment/comment_manage');
        }else{
            return $this->error('删除失败！','comment/comment_manage');
        }

    }
}
